package org.marsdonne.auth.resolver;

import graphql.kickstart.tools.GraphQLQueryResolver;
import org.marsdonne.auth.AuthUtils;
import org.marsdonne.auth.EndPointUser;
import org.marsdonne.auth.EndPointUserRepos;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class UserQueryResolver implements GraphQLQueryResolver {

    @Resource
    private EndPointUserRepos repos;

    public EndPointUser currentUser() {
        String identifier = AuthUtils.getCurrentUser().getUsername();
        return this.repos.findByIdentifier(identifier).orElse(null);
    }

    public EndPointUser specifiedUser(String identifier) {
        return this.repos.findByIdentifier(identifier).orElse(null);
    }
}
